package Arrays101.Day03;

import java.util.HashSet;

public class Day03_2 {
    public static void main(String[] args) {
        removeDuplicates(new int[]{-3,-1,0,0,0,3,3});
    }

    /**
     * Remove Duplicates from Sorted Array
     *
     * Given a sorted array nums, remove the duplicates in-place
     * such that each element appears only once and returns the new length.
     * Do not allocate extra space for another array,
     * you must do this by modifying the input array in-place with O(1) extra memory.
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums){

        HashSet<Integer> hashSet = new HashSet<>();

        for (int i = 0; i < nums.length; i++) {
            hashSet.add(nums[i]);
        }
        Object[] objects = hashSet.toArray();
        for (int i = 0; i < objects.length; i++) {
            for (int j = 0; j < objects.length-i-1; j++) {
                int temp=0;
                if ((int)objects[j]>(int)objects[j+1]){
                    temp= (int) objects[j];
                    objects[j]=objects[j+1];
                    objects[j+1]=temp;
                }
            }
        }

        for (int i = 0; i < objects.length; i++) {
            nums[i]= (int) objects[i];
        }

        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]);
        }
        return objects.length;
    }
}
